package org.lex.ftp.net;

import org.apache.commons.net.ProtocolCommandEvent;
import org.apache.commons.net.ftp.FTPFile;
import org.lex.net.event.ProtocolEvent;
import org.lex.net.ftp.IFTPFile;

public class Adapters {
	public static ProtocolEvent adapt(ProtocolCommandEvent e) {
		if (e.isCommand()) {
			return new ProtocolEvent(e.getSource(), e.getCommand(), e.getMessage());
		} else {
			return new ProtocolEvent(e.getSource(), e.getReplyCode(), e.getMessage());
		}
	}

	public static IFTPFile adapt(String pwd, FTPFile file) {
		return new org.lex.net.ftp.FTPFile(pwd, file.getName(), file.getSize(), file.getTimestamp().getTimeInMillis(), getAttribute(file),
				file.isDirectory());
	}

	private static String getAttribute(FTPFile file) {
		return "---";
	}

	private Adapters() {
	}
}
